import * as path from "path";
import { Caller } from "../client";
import { ProtoGrpcType } from "../../demo/proto/sample";

const protoPath = path.resolve(__dirname, "./proto/sample.proto");
const logs: string[] = [];

async function main() {
  const caller = new Caller<ProtoGrpcType>(protoPath);
  const greeterService = caller.link(
    (p) => p.helloworld.Greeter,
    "localhost:50051"
  );

  const t1 = Date.now();
  for (let i = 0; i < 1000; i++) {
    const { message } = await greeterService.SayHello({ name: "your name" });
    greeterService.SayHelloB();
    greeterService.sayHelloC();
    greeterService.sayHelloS();
    logs.push(`[${i}]: ${message}`);
  }
  const t2 = Date.now();
  console.log(logs.join("\n"));
  console.log(`cost ${t2 - t1}ms`);
}

main();
